/**
 * 移动端报修功能API接口
 * @author Wu.Liang
 * @date 2025-01-27
 */

import request from '@/api/request'

// 报修相关API
export const repairApi = {
  // 提交报修申请
  submitRepair: (data) => {
    return request.post('/api/property/repair-orders/mobile/submit', data)
  },
  
  // 文件上传
  uploadFile: (filePath, uploadType = 'IMAGE', uploadSource = 'APP') => {
    const formData = {
      uploadType: uploadType,
      uploadSource: uploadSource
    }
    return request.upload('/api/user/upload', filePath, 'file', formData)
  },

  // 获取我的报修记录
  getMyRepairOrders: (params) => {
    return request.get('/api/property/repair-orders/mobile/my-orders', params)
  },

  // 获取报修详情
  getRepairDetail: (orderId) => {
    return request.get(`/api/property/repair-orders/mobile/${orderId}/detail`)
  },

  // 获取报修类型列表
  getRepairTypes: () => {
    return request.get('/api/property/repair-orders/types')
  },

  // 获取位置列表
  getLocationList: () => {
    return request.get('/api/property/repair-orders/locations')
  },

  // 获取当前用户的房户列表
  getMyHouseholds: () => {
    return request.get('/api/region/resident/mobile/my-households')
  },

  // 获取报修进度记录
  getRepairProgress: (orderId) => {
    return request.get('/api/property/repair-progress/list', { orderId })
  },

  // 提交满意度评分
  submitRating: (orderId, satisfaction) => {
    return request.post(`/api/property/repair-orders/${orderId}/rating`, { satisfaction })
  },

  // 取消报修
  cancelRepair: (orderId, reason) => {
    return request.put(`/api/property/repair-orders/${orderId}/cancel?reason=${encodeURIComponent(reason)}`)
  }
}

// 报修类型常量
export const REPAIR_TYPES = [
  { value: 1, label: '水电维修' },
  { value: 2, label: '门窗维修' },
  { value: 3, label: '电梯维修' },
  { value: 4, label: '空调维修' },
  { value: 5, label: '其他问题' }
]

// 紧急程度常量
export const URGENCY_LEVELS = [
  { value: 'low', label: '一般' },
  { value: 'medium', label: '紧急' },
  { value: 'high', label: '非常紧急' }
]

// 报修状态常量
export const REPAIR_STATUS = {
  PENDING: 1,
  ACCEPTED: 2,
  PROCESSING: 3,
  COMPLETED: 4,
  CANCELLED: 5
}

// 状态文本映射
export const STATUS_TEXT_MAP = {
  1: '待受理',
  2: '已受理',
  3: '维修中',
  4: '已完成',
  5: '已取消'
}

// 状态类型映射
export const STATUS_TYPE_MAP = {
  1: 'info',
  2: 'warning',
  3: 'primary',
  4: 'success',
  5: 'error'
}
